package me.nibo.tree;

import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import me.nibo.tree.bean.OrgBean;


public class MainActivity extends ActionBarActivity {

    private ListView mTree;
    private SimpleTreeListViewAdapter<OrgBean> viewAdapter;
    private List<OrgBean> datas;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initDatas();
        mTree = (ListView) findViewById(R.id.lv_tree);
        try {
            viewAdapter = new SimpleTreeListViewAdapter<>(this, datas, 10, mTree);
            mTree.setAdapter(viewAdapter);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }

    private void initDatas() {
        datas = new ArrayList<>();
        OrgBean orgBean = new OrgBean("1", "组织1");
        datas.add(orgBean);
        orgBean = new OrgBean("2", "1", "组织1-1");
        datas.add(orgBean);
        orgBean = new OrgBean("3", "组织2");
        datas.add(orgBean);
        orgBean = new OrgBean("4", "组织3");
        datas.add(orgBean);
        orgBean = new OrgBean("5", "2", "组织1-1-1");
        datas.add(orgBean);
        orgBean = new OrgBean("6", "2", "组织1-1-2");
        datas.add(orgBean);
        orgBean = new OrgBean("7", "4", "组织3-1");
        datas.add(orgBean);
    }

}
